package com.ddpt.permission.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lh.center.common.base.BizServiceImpl;
import com.lh.center.common.constant.GlobalConstant;
import com.lh.center.permission.api.entity.BackAdminUser;
import com.lh.center.permission.mapper.BackAdminUserMapper;
import com.lh.center.permission.service.BackAdminUserService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * SaaS后台用户表 服务实现类
 * </p>
 *
 * @author czy
 * @since 2022-04-07
 */
@Service
public class BackAdminUserServiceImpl extends BizServiceImpl<BackAdminUserMapper, BackAdminUser> implements BackAdminUserService {
    public static void main(String[] args) {
        System.out.println(DigestUtil.md5Hex("back123456"));
        // saas 账号是 backadmin 密码是 back123456
    }
    @Override
    public BackAdminUser getAvailableUserByUsernameAndPassword(String account, String password) {
        LambdaQueryWrapper<BackAdminUser> wrapper = Wrappers.lambdaQuery(BackAdminUser.class);
        wrapper.eq(BackAdminUser::getUsername,account);
        wrapper.eq(BackAdminUser::getPassword, DigestUtil.md5Hex(password));
        wrapper.eq(BackAdminUser::getStatus, GlobalConstant.ONE);
        wrapper.eq(BackAdminUser::getDeleted,GlobalConstant.ZERO);
        return getOne(wrapper);
    }
}
